"""
五秒盾
"""
from DrissionPage import ChromiumOptions, WebPage

base_url = 'https://rucaptcha.com/42'


def crack_5sd():
    dp = ChromiumOptions()
    # dp.incognito()  # 匿名模式，开启过不了
    dp.headless()  # 无头模式
    # dp.set_argument('--no-sandbox')  # 无沙盒模式
    # dp.set_argument('--disable-gpu')  # 禁用gpu加速
    dp.set_argument('--start-maximized')  # 设置启动时最大化
    dp.set_user_agent(
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36')
    page = WebPage(mode='d', chromium_options=dp)
    page.get(base_url)

    try:
        # 验证可能需要一段时间
        while True:
            if '正在验证您是否是真人' in page.html:
                page.wait(2)
            else:
                break
        try:
            div = page.ele('x:div.container').html
        except Exception as e:
            print(e)
            div = page.html
        print(div)
        print('破解结果: {}'.format('失败' if '请稍候…' in div else '成功'))
    finally:
        page.quit()


if __name__ == '__main__':
    crack_5sd()
